import { lookResumeListForUser, lookPostList, lookOneResume, addOneResume, updateResume, deleteResume, submitResume } from '@/api/resume'

const getDefaultState = () => {}

const state = getDefaultState()

const mutations = {}

const actions = {
  // 获取简历列表
  lookResumeListForUser({ commit }, { current, size, userId }) {
    return new Promise((resolve, reject) => {
      lookResumeListForUser(current, size, userId)
        .then((res) => {
          resolve(res)
        })
        .catch((err) => {
          reject(err)
        })
    })
  },
  // 提交简历
  submitResume({ commit }, { postId, resumeId }) {
    return new Promise((resolve, reject) => {
      submitResume(postId, resumeId)
        .then((response) => {
          resolve(response)
        })
        .catch((err) => {
          reject(err)
        })
    })
  },

  // 获取简历列表
  lookResumeList({ commit }, postId) {
    return new Promise((resolve, reject) => {
      lookResumeList(postId)
        .then((res) => {
          resolve(res)
        })
        .catch((err) => {
          reject(err)
        })
    })
  },
  // 获取岗位列表
  lookPostList({ commit }, { current, size, userId }) {
    return new Promise((resolve, reject) => {
      lookPostList(current, size, userId)
        .then((res) => {
          resolve(res)
        })
        .catch((err) => {
          reject(err)
        })
    })
  },
  // 获取简历
  lookOneResume({ commit }, id) {
    return new Promise((resolve, reject) => {
      lookOneResume(id)
        .then((res) => {
          resolve(res)
        })
        .catch((err) => {
          reject(err)
        })
    })
  },
  // 添加简历
  addOneResume({ commit }, data) {
    return new Promise((resolve, reject) => {
      addOneResume(data)
        .then((res) => {
          resolve(res)
        })
        .catch((err) => {
          reject(err)
        })
    })
  },
  // 更新简历
  updateResume({ commit }, data) {
    return new Promise((resolve, reject) => {
      updateResume(data)
        .then((res) => {
          resolve(res)
        })
        .catch((err) => {
          reject(err)
        })
    })
  },
  // 删除简历
  deleteResume({ commit }, id) {
    return new Promise((resolve, reject) => {
      deleteResume(id)
        .then((res) => {
          resolve(res)
        })
        .catch((err) => {
          reject(err)
        })
    })
  },
}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
}
